package com.woniuxy.java106crm.service.impl;

import com.woniuxy.java106crm.entity.DataDictionary;
import com.woniuxy.java106crm.mapper.DictionaryMapper;
import com.woniuxy.java106crm.service.DictionaryService;
import com.woniuxy.java106crm.vo.GradeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Service
public class DictionaryServiceImpl implements DictionaryService {
    //mapper注入
    @Resource
    private DictionaryMapper dictionaryMapper;

    @Override
    public List<DataDictionary> findDataDictByType(String type) {
        return dictionaryMapper.findDataDictByType(type);
    }

    //添加基础数据
    @Override
    public Boolean addData(DataDictionary dataDictionary) {
        return dictionaryMapper.addData(dataDictionary);
    }

    //修改基础数据
    @Override
    public Boolean editData(DataDictionary dataDictionary) {
        return dictionaryMapper.editData(dataDictionary);
    }

    //删除基础数据
    @Override
    public Boolean delData(Integer id) {
        return dictionaryMapper.delData(id);
    }

    //批量删除
    @Override
    public Boolean putchDel(String ids) {
        Boolean flag = false;
        //拆分字符串
        String[] idsData = ids.split(",");
        //遍历数组
        for(String id : idsData){
            //调用dao层方法：根据id 删除信息
            flag = dictionaryMapper.delData(Integer.valueOf(id));
        }
        return flag;

    }

    //查询所有客户等级
    @Override
    public List<GradeVo> getGrade() {
        return dictionaryMapper.getGrade();
    }
}
